﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SuperMap.HB.ThemeWork
{
    public partial class MessageTipForm : Form
    {
        private BackgroundWorker m_Worker;
        //private delegate void SetTextHandler(string text);

        public MessageTipForm(BackgroundWorker backgroundWorker)
        {
            InitializeComponent();
            if (backgroundWorker != null)
            {
                m_Worker = backgroundWorker;
                m_Worker.ProgressChanged += M_Worker_ProgressChanged;
                m_Worker.RunWorkerCompleted += M_Worker_RunWorkerCompleted;
                Text = "处理进度";
            }
            else
            {
                lbl_CurrentPrecent.Visible = false;
                lbl_Title.Visible = false;
                pb_CurrentPrecent.Style = ProgressBarStyle.Marquee;
                Text = "数据处理中，请稍后...";
            }
            CheckForIllegalCrossThreadCalls = false;
            //SetText("正在执行，请耐心等待....");

        }
        //public void SetText(string text)
        //{
        //    if (this.label1.InvokeRequired)
        //    {
        //        this.Invoke(new SetTextHandler(SetText), text);
        //    }
        //    else
        //    {
        //        this.label1.Text = text;
        //    }
        //}

        private void M_Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                Close();
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
        }

        private void M_Worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            try
            {
                pb_CurrentPrecent.Value = e.ProgressPercentage;
                lbl_CurrentPrecent.Text = e.ProgressPercentage + "%";
                lbl_Title.Text = e.UserState.ToString();
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
        }
    }
}
